home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Graphic Elements 3 / GEMisc / LGEPane.cp < prev    next >
Text File  |  1995-06-01  |  2KB  |  124 lines

  1. // ===========================================================================
  2. //    LGEPane.cp                    ©1994 by Al Evans. All rights reserved.
  3. // ===========================================================================
  4.  
  5. #include "LGEPane.h"
  6. #include "GEWorldManager.h"
  7.  
  8. LGEPane*    LGEPane::CreateLGEPaneStream(LStream *inStream)
  9. {
  10.     return (new LGEPane(inStream));
  11. }
  12.  
  13. LGEPane::LGEPane(LStream *inStream)
  14.         :LPane(inStream)
  15. {
  16.     mGEWorld = nil;
  17.     mSubstitutePICT = 0;
  18.     mLoaded = false;
  19.     MakeWorld();
  20. }
  21.  
  22. LGEPane::LGEPane()
  23.         :LPane()
  24. {
  25.     mGEWorld = nil;
  26.     mSubstitutePICT = 0;
  27.     mLoaded = false;
  28. }
  29.  
  30. LGEPane::LGEPane(const SPaneInfo &inPaneInfo, GEWorldLoader loadProc)
  31.         : LPane(inPaneInfo)
  32. {
  33.     mGEWorld = nil;
  34.     mSubstitutePICT = 0;
  35.     mLoaded = false;
  36.     if (MakeWorld()) {
  37.         if (loadProc != nil)
  38.             LoadWorld(loadProc);
  39.     }
  40. }
  41.  
  42. LGEPane::~LGEPane()
  43. {
  44.     DisposeWorld();
  45. }
  46.  
  47. Boolean LGEPane::MakeWorld()
  48. {
  49.     Rect    paneFrame;
  50.     
  51.     DisposeWorld();
  52.     CalcPortFrameRect(paneFrame);
  53.     mGEWorld = NewGEWorld(GetMacPort(), &paneFrame, scaleOneToOne, nil);
  54.     if (mGEWorld != nil)
  55.         (void) AddToWorldList(mGEWorld, true);
  56.     return (mGEWorld != nil);
  57. }
  58.  
  59. void  LGEPane::DisposeWorld()
  60. {
  61.     if (mGEWorld != nil) {
  62.         StopRepeating();
  63.         DisposeGEWorld(mGEWorld);
  64.     }
  65.     mGEWorld = nil;
  66. }
  67.  
  68. Boolean LGEPane::LoadWorld(GEWorldLoader loadProc)
  69. {
  70.     Boolean    loaded;
  71.     if ((mGEWorld == nil) || (loadProc == nil))
  72.         loaded = false;
  73.     else
  74.         loaded = (loadProc)(mGEWorld);
  75.     if (loaded) {
  76.         ActivateWorld(mGEWorld, true);
  77.         StartRepeating();
  78.     }
  79.     mLoaded = loaded;
  80.     return loaded;
  81. }        
  82.  
  83. void LGEPane::SetSubstitutePICT(ResIDT pictResNum)
  84. {
  85.     mSubstitutePICT = pictResNum;
  86. }
  87.  
  88. GEWorldPtr LGEPane::GetGEWorld()
  89. {
  90.     return mGEWorld;
  91. }
  92.             
  93. void LGEPane::SpendTime(const EventRecord &inMacEvent)
  94. {
  95.     if ((mGEWorld != nil) && mLoaded)
  96.         DoWorldUpdate(mGEWorld, false);
  97. }
  98.  
  99. void LGEPane::DrawSelf()
  100. {
  101.     if ((mGEWorld != nil) && mLoaded)
  102.         DoWorldUpdate(mGEWorld, true);
  103.     else
  104.         if (mSubstitutePICT != 0) {
  105.             PicHandle    macPictureH = GetPicture(mSubstitutePICT);
  106.             if (macPictureH != nil) {
  107.                 Rect    pictureBounds = (**macPictureH).picFrame;
  108.                 Rect    paneFrame;
  109.                 CalcPortFrameRect(paneFrame);
  110.                 OffsetRect(&pictureBounds, paneFrame.left, paneFrame.top);
  111.                 ::DrawPicture(macPictureH, &pictureBounds);
  112.                 
  113.             }
  114.         }
  115. }
  116.  
  117. void LGEPane::ClickSelf(const SMouseDownEvent &inMouseDown)
  118. {
  119.     Boolean    unused;
  120.     
  121.     if (mGEWorld != nil)
  122.         unused = MouseDownInSensor(mGEWorld, inMouseDown.macEvent.where);
  123. }
  124.